home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 1 / LIGHT-ROM 1 (Amiga Library Services)(1994).iso / ffdisks / d974.lha / DDLI / ddli.c < prev    next >
C/C++ Source or Header  |  1994-01-05  |  10KB  |  316 lines

  1. /*
  2.  *  ddli.c
  3.  *  The Duniho and Duniho Life Pattern Indicator
  4.  *  by Fergus Duniho
  5.  *  Copyright (c) 1992-1994 Fergus Duniho
  6.  */
  7.  
  8. #define VER "V3.10"
  9. #define EMAIL "fdnh@troi.cc.rochester.edu"
  10.  
  11. #define DICE 0
  12.  
  13. #define AMIGA 1
  14. #define MSDOS 2
  15. #define OTHER 3
  16.  
  17. #define OPSYS AMIGA
  18.  
  19. #if OPSYS == AMIGA
  20.     #define prtdev "PRT:"
  21.     #define FILE_NAME_MAX 32
  22. #elif OPSYS == MSDOS
  23.     #define prtdev "PRN"
  24.     #define FILE_NAME_MAX 8
  25. #elif OPSYS == OTHER
  26.     #define prtdev ""
  27.     #define FILE_NAME_MAX 16
  28. #else
  29.     #error OPERATING SYSTEM UNKNOWN
  30. #endif
  31.  
  32. /*
  33.  * If your compiler does not have the command "strdup",
  34.  * which is common in C compilers but not part of ANSI
  35.  * C, uncomment the next #include statement.
  36.  */
  37. /* #include "strdup.c" */
  38.  
  39. #include "fpdio.c"
  40. #include "qst.c"
  41. #include <time.h>
  42.  
  43. #define XN E ? "Extraverted" : "Introverted"
  44. #define QFILE "DDLI.QST"
  45.  
  46. int pow (int x, int y);
  47.  
  48. main (int argc, char **argv) {
  49.     int i, col, size, A, pr[14], x,
  50.         E, I, S, N, T, F, J, P, ES, EN, ET, EF, R;
  51.     char line[256], nline[512], *type, *name, *fname, *Version,
  52.          LP[5], LPE[5], LPI[5],
  53.          *PF[2] = {"Intuition", "Sensing"},
  54.          *JF[2] = {"Thinking", "Feeling"},
  55.          *text1 = "Your %s function is %s %s.";
  56.     FILE *fptr;
  57.     qst *Q;
  58.  
  59. #if OPSYS == MSDOS
  60.     col = 75;
  61. #else
  62.     wrapwrite (stdout, 0, 0, 20, "How many columns does your screen have?", 0);
  63.     col = fgetp(stdin);
  64. #endif
  65.  
  66.     wrapwrite (stdout, 0, 0, col,
  67.         "\n\"The Duniho and Duniho Life Pattern Indicator\"",
  68.         VER, "\nBy Fergus Duniho. Copyright (c) 1992, 1993",
  69.         "Fergus Duniho.\n\nMost of the questions are drawn from",
  70.         "and based on those in Terence Duniho's \"Preference",
  71.         "Patterns Questionaire\" and his book _Wholeness Lies",
  72.         "Within_. Fergus is responsible for the choice of questions.",
  73.         "\n\nThis product is freeware. Send comments, bug reports,",
  74.         "reports on accuracy, and suggestions for improvement to",
  75.         "Fergus Duniho at the following address:\n\n", EMAIL, 0);
  76.  
  77.     size = Linefeeds(QFILE) / 3;
  78.     Q = new_qnode(0);
  79.     Q->pv = Q->nx = Q;
  80.     Version = Get_QList (QFILE, Q, size);
  81.  
  82.     wrapwrite (stdout, 0, 0, col, "\nWhat is your name?", 0);
  83.     name = clone_line(stdin, 80);
  84.  
  85. #ifdef DEBUG
  86.     wrapwrite (stdout, 0, 0, col,
  87.         "Enter an integer as a seed value for the random # generator", 0);
  88.     srand (fgetp(stdin));
  89. #else
  90.     srand (clock());
  91. #endif
  92.  
  93.     for (i = 0; i < 14; i++) /* Initializes Preference Scores to Zero */
  94.         pr[i] = 0;
  95.  
  96.     if (argc == 1) {
  97.         Q = RND_QList (Q, size);
  98.         AskQuestions (Q, col);
  99.         for (Q = Q->nx; Q->num > 0; Q = Q->nx) /* Calculates Scores */
  100.             pr[Q->ans] += Q->strength;
  101.     }
  102.     else {
  103.         RdOpen (fptr, argv[1]);
  104.         while (fgetc(fptr) != '\n');
  105.         while (fgetc(fptr) != '\n');
  106.         while (fgetp(fptr) != EOF) {
  107.             i = fgetp(fptr);
  108.             pr[i] += fgetp(fptr);
  109.         }
  110.     }
  111.  
  112. #if OPSYS == OTHER
  113.     wrapwrite (stdout, 0, 0, col,
  114.         "Send output to (1) Screen or (2) File?", 0);
  115. #else
  116.     wrapwrite (stdout, 0, 0, col,
  117.         "Send output to (1) Screen, (2) File or (3) Printer?", 0);
  118. #endif
  119.     do {
  120.         A = fgetp(stdin);
  121.         if (A == 1)
  122.             fptr = stdout;
  123.         else if (A == 2) {
  124.             wrapwrite (stdout, 0, 0, col, "Please enter a file name.", 0);
  125.             fname = clone_line(stdin, FILE_NAME_MAX);
  126.             WrOpen (fptr, fname);
  127.         }
  128. #if OPSYS != OTHER
  129.         else if (A == 3) {
  130.             WrOpen (fptr, prtdev);
  131.             col = 75;
  132.         }
  133. #endif
  134.         else
  135. #if OPSYS == OTHER
  136.             wrapwrite (stdout, 0, 0, col, "Please enter a 1 or a 2.", 0);
  137. #else
  138.             wrapwrite (stdout, 0, 0, col,
  139.                 "Please enter a 1, a 2, or a 3.", 0);
  140. #endif
  141.     } while (A < 1 || A > 3);
  142.  
  143.     E = pr[1]; I = pr[2]; S = pr[3]; N = pr[4];
  144.     T = pr[5]; F = pr[6]; J = pr[7]; P = pr[8];
  145.     ES = pr[12]; EN = pr[13]; ET = pr[11]; EF = pr[10];
  146.     sprintf (nline, "%s's scores on the main set of questions:\n"
  147.                     "\nExtraversion (E): %3d    %3d :(I) Introversion"
  148.                     "\nSensing      (S): %3d    %3d :(N) iNtuition"
  149.                     "\nThinking     (T): %3d    %3d :(F) Feeling"
  150.                     "\nJudging      (J): %3d    %3d :(P) Perceiving\n",
  151.                     name, E, I, S, N, T, F, J, P);
  152.     wrapwrite (fptr, 0, 0, col, nline, 0);
  153.  
  154.     /* Calculates possible life pattern based on primary scores. */
  155.     LP[0] = (E > I) ? 'E' : (E < I) ? 'I' : 'X';
  156.     LP[1] = (S > N) ? 'S' : (S < N) ? 'N' : 'X';
  157.     LP[2] = (T > F) ? 'T' : (T < F) ? 'F' : 'X';
  158.     LP[3] = (J > P) ? 'J' : (J < P) ? 'P' : 'X';
  159.     LP[4] = 0;
  160.  
  161.     fprintf (fptr, "You scored as an %s.\n", LP);
  162.     x = 0;
  163.     for (i = 0; i < 4; i++)
  164.         if (LP[i] == 'X')
  165.             x++;
  166.     if (x) {
  167.         sprintf (line, "This is not a real type. You could be any of"
  168.         "%d different types. Read the type descriptions to determine "
  169.         "which you are.", pow(2,x));
  170.         wrapwrite (fptr, 0, 0, col, line, 0);
  171.     }
  172.     else {
  173.         E = (LP[0] == 'E'); R = ((LP[3] == 'J') == E);
  174.         sprintf (line, "\nAssuming that you are an %s,\n", LP);
  175.         wrapwrite (fptr, 0, 5, col, line, 0);
  176.         sprintf (line, text1, "DOMINANT", XN, R ? JF[LP[2] == 'F'] : PF[LP[1] == 'S']);
  177.         wrapwrite (fptr, 0, 5, col, line, 0);
  178.         sprintf (line, text1, "AUXILIARY", !XN, R ? PF[LP[1] == 'S'] : JF[LP[2] == 'F']);
  179.         wrapwrite (fptr, 0, 5, col, line, 0);
  180.         sprintf (line, text1, "TERTIARY", XN, R ? PF[LP[1] == 'N'] : JF[LP[2] == 'T']);
  181.         wrapwrite (fptr, 0, 5, col, line, 0);
  182.         sprintf (line, text1, "INFERIOR", !XN, R ? JF[LP[2] == 'T'] : PF[LP[1] == 'N']);
  183.         wrapwrite (fptr, 0, 5, col, line, 0);
  184.     }
  185.     if (A == 1) {
  186.         wrapwrite (stdout, 0, 0, col, "Hit <ENTER> or <RETURN> to see",
  187.             "your results on the supplementary questions.", 0);
  188.         while (fgetc(stdin) != '\n');
  189.     }
  190.     sprintf (nline, "\n%s's scores on the supplementary questions:\n\n"
  191.     "Extraverted Thinking / Introverted Feeling   : %d\n"
  192.     "Extraverted Feeling / Introverted Thinking   : %d\n\n"
  193.     "Extraverted Intuition / Introverted Sensing  : %d\n"
  194.     "Extraverted Sensing / Introverted Intuition  : %d\n\n"
  195.     "Rationality (Dominant Judging Function)      : %d\n"
  196.     "A-rationality (Dominant Perceiving Function) : %d\n\n",
  197.         name, ET, EF, EN, ES, pr[9], pr[0]);
  198.     wrapwrite (fptr, 0, 0, col, nline, 0);
  199.  
  200.     /* Calculates possible life patterns based on supplemental scores. */
  201.     LPE[0] = 'E'; LPI[0] = 'I';
  202.     if (pr[9] > pr[0]) {
  203.         LPE[3] = 'J';
  204.         LPI[3] = 'P';
  205.     }
  206.     else if (pr[9] < pr[0]) {
  207.         LPE[3] = 'P';
  208.         LPI[3] = 'J';
  209.     }
  210.     else {
  211.         LPE[3] = 'X';
  212.         LPI[3] = 'X';
  213.     }
  214.     if (LPE[3] == 'P') {
  215.         if (EF > ET) {
  216.             LPE[2] = 'T';
  217.             LPI[2] = 'F';
  218.         }
  219.         else if (EF < ET) {
  220.             LPE[2] = 'F';
  221.             LPI[2] = 'T';
  222.         }
  223.         else {
  224.             LPE[2] = 'X';
  225.             LPI[2] = 'X';
  226.         }
  227.         if (ES < EN) {
  228.             LPE[1] = 'N';
  229.             LPI[1] = 'S';
  230.         }
  231.         else if (ES > EN) {
  232.             LPE[1] = 'S';
  233.             LPI[1] = 'N';
  234.         }
  235.         else {
  236.             LPE[1] = 'X';
  237.             LPI[1] = 'X';
  238.         }
  239.     }
  240.     else if (LPE[3] == 'J') {
  241.         if (EF < ET) {
  242.             LPE[2] = 'T';
  243.             LPI[2] = 'F';
  244.         }
  245.         else if (EF > ET) {
  246.             LPE[2] = 'F';
  247.             LPI[2] = 'T';
  248.         }
  249.         else {
  250.             LPE[2] = 'X';
  251.             LPI[2] = 'X';
  252.         }
  253.         if (ES > EN) {
  254.             LPE[1] = 'N';
  255.             LPI[1] = 'S';
  256.         }
  257.         else if (ES < EN) {
  258.             LPE[1] = 'S';
  259.             LPI[1] = 'N';
  260.         }
  261.         else {
  262.             LPE[1] = 'X';
  263.             LPI[1] = 'X';
  264.         }
  265.     }
  266.     else {
  267.         LPE[1] = 'X';
  268.         LPE[2] = 'X';
  269.         LPI[1] = 'X';
  270.         LPI[2] = 'X';
  271.     }
  272.     LPE[4] = LPI[4] = 0;
  273.  
  274.     sprintf (line, "According to the supplementary scores, %s could be "
  275.     "an %s or an %s.", name, LPE, LPI);
  276.     if ((strcmp(LP, LPE) == 0) || (strcmp(LP, LPI) == 0))
  277.         sprintf (nline, "%s These results corroborate your score as an %s.", line, LP);
  278.     else
  279.         sprintf (nline, "%s These results conflict with the evaluation of %s as an %s.", line, name, LP);
  280.     wrapwrite (fptr, 5, 0, col, nline, "\n\n", 0);
  281.     if (fptr != stdout)
  282.         fclose (fptr);
  283.     if (argc == 1) {
  284.         wrapwrite (stdout, 5, 0, col, "With your permission, this program",
  285.             "will now record your raw scores in a file. To further the",
  286.             "reliability of this program, I would like you to save a copy",
  287.             "of this record and email it to me at", EMAIL, "through "
  288.             "the Internet, or through my personal email account on the "
  289.             "FileWorks BBS in Rochester, NY. Do you give this program your "
  290.             "permission to save this record? (y/n)", 0);
  291.  
  292.         if (yesno() == 1) {
  293.             wrapwrite (stdout, 0, 0, col, "What will you name this file?\n", 0);
  294.             free (fname);
  295.             fname = clone_line(stdin, FILE_NAME_MAX);
  296.             wrapwrite (stdout, 0, 0, col,
  297.                 "What is your psychological type?\n", 0);
  298.             type = clone_line(stdin, 4);
  299.             printf ("\nSending raw scores to \"%s\".\n", fname);
  300.             WrOpen (fptr, fname);
  301.             fprintf (fptr, "%s\n%s\n", Version, type);
  302.             for (Q = Q->nx; Q->num > 0; Q = Q->nx)
  303.                 fprintf (fptr, "%d %d %d\n", Q->num, Q->ans, Q->strength);
  304.             fclose (fptr);
  305.         }
  306.     }
  307. }
  308.  
  309. int pow (int x, int y) {
  310.     if (y < 1)
  311.         return 1;
  312.     if (y == 1)
  313.         return x;
  314.     return x * pow(x, y-1);
  315. }
  316.